package com.ding.easycontroller.filter;

import easycontroller.plugin.expand.GatewayPlugin;
import org.springframework.boot.web.servlet.filter.OrderedFilter;
import org.springframework.stereotype.Component;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

//@Component
public class TestFilter implements OrderedFilter {


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        Map<String, String> config = new HashMap<>();

        config.put("GET /test", "{time:\"default\",target:\"http://www.baidu.com\"}");

        GatewayPlugin gatewayPlugin = new GatewayPlugin();

        gatewayPlugin.setConfig(config);

        gatewayPlugin.start();

        gatewayPlugin.onDefault((HttpServletRequest) servletRequest,(HttpServletResponse) servletResponse);

        servletResponse.getOutputStream().flush();

    }




    @Override
    public int getOrder() {
        return Integer.MIN_VALUE;
    }
}
